Option Strict Off
Option Explicit On
Friend Class PickActions
	Inherits System.Windows.Forms.Form
	
	Dim default_sets(100, 12) As Short
	Dim default_set_count As Short
	
	Private Sub cmdSave_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSave.Click
		' makes sure there are no duplicates
		Dim i As Object
		Dim j As Short
		For i = 0 To 11
			'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			For j = i + 1 To 11
				If lstActions(i).Text = lstActions(j).Text And lstActions(i).Text <> "Random" Then
					MsgBox("You have chosen duplicate actions.  Please fix this.")
					Exit Sub
				End If
			Next j
		Next i
		
		' make sure at least one set if checked
		If chkSetB.CheckState = 0 And chkSetS.CheckState = 0 And chkSetI.CheckState = 0 And chkSetA.CheckState = 0 Then
			MsgBox("You must check at least one of the sets.")
			Exit Sub
		End If
		
		
		FileOpen(1, My.Application.Info.DirectoryPath & "/actions.txt", OpenMode.Output)
		For i = 0 To 11
			PrintLine(1, lstActions(i).Text)
		Next i
		PrintLine(1, chkAlchemy.CheckState)
		PrintLine(1, chkSetB.CheckState)
		PrintLine(1, chkSetS.CheckState)
		PrintLine(1, chkSetI.CheckState)
		PrintLine(1, chkSetA.CheckState)
		
		For i = 0 To num_all_actions - 8
			PrintLine(1, chkCard(i).CheckState)
		Next i
		PrintLine(1, 1)
		FileClose(1)
		
		Me.Hide()
	End Sub
	
	Public Sub PickActions_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		' load dropdowns with all actions
		Dim j, i, offsetX As Object
		Dim offsetY As Short
		'UPGRADE_NOTE: str was upgraded to str_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
		Dim str_Renamed As String
		
		For j = 0 To 11
			lstActions(j).Items.Clear()
			lstActions(j).Items.Add(("Random"))
			For i = 7 To num_all_actions + 6
				'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				If names(i) <> "Potion" Then lstActions(j).Items.Add((get_sorted_name_by_id(i)))
			Next i
		Next j
		
		For i = 7 To num_all_actions + 6
			'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			'UPGRADE_WARNING: Couldn't resolve default property of object j. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			j = i - 7
			'UPGRADE_WARNING: Couldn't resolve default property of object get_id_by_name(Potion). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			'UPGRADE_WARNING: Couldn't resolve default property of object i. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			'UPGRADE_WARNING: Couldn't resolve default property of object j. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			If i > get_id_by_name("Potion") Then j = j - 1
			'UPGRADE_WARNING: Couldn't resolve default property of object j. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			If j > chkCard.UBound Then
				chkCard.Load(j)
				lblCard.Load(j)
			End If
			'UPGRADE_WARNING: Couldn't resolve default property of object j. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			If j > lblCard.UBound Then
				lblCard.Load(j)
			End If
			
			'UPGRADE_WARNING: Couldn't resolve default property of object j. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			'UPGRADE_WARNING: Mod has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
			'UPGRADE_WARNING: Couldn't resolve default property of object offsetX. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			offsetX = 1600 * (j Mod 7)
			'UPGRADE_WARNING: Couldn't resolve default property of object j. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			offsetY = 300 * Int(j / 7)
			
			chkCard(j).Visible = True
			'UPGRADE_WARNING: Couldn't resolve default property of object offsetX. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			chkCard(j).SetBounds(VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(chkCard(0).Left) + offsetX), VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(chkCard(0).Top) + offsetY), 0, 0, Windows.Forms.BoundsSpecified.X Or Windows.Forms.BoundsSpecified.Y)
			'UPGRADE_WARNING: Couldn't resolve default property of object j. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			chkCard(j).Text = VB6.GetItemString(lstActions(0), j)
			chkCard(j).BringToFront()
			'UPGRADE_WARNING: Couldn't resolve default property of object j. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			'UPGRADE_WARNING: Couldn't resolve default property of object get_id_by_name(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			If not_coded(get_id_by_name(Mid(VB6.GetItemString(Me.lstActions(0), j), 5))) = 1 Then
				chkCard(j).CheckState = System.Windows.Forms.CheckState.Unchecked
				chkCard(j).Enabled = False
			End If
		Next i
		
		' load presets from a file
		Dim set_item As Short
		set_item = 0
		default_set_count = -1
		FileOpen(1, My.Application.Info.DirectoryPath & "/sets.txt", OpenMode.Input)
		Do While Not EOF(1)
			Input(1, str_Renamed)
			If InStr(str_Renamed, ":") > 0 Then
				default_set_count = default_set_count + 1
				set_item = 0
				lstPreset.Items.Add(Mid(str_Renamed, 1, Len(str_Renamed) - 1))
				'UPGRADE_WARNING: Couldn't resolve default property of object get_id_by_name(str_Renamed). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			ElseIf get_id_by_name(str_Renamed) > -1 Then 
				'UPGRADE_WARNING: Couldn't resolve default property of object get_id_by_name(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				default_sets(default_set_count, set_item) = get_id_by_name(str_Renamed)
				set_item = set_item + 1
			End If
		Loop 
		lstPreset.SelectedIndex = 0
		FileClose(1)
		
		' hide boxes that are not available
		For i = 0 To CDbl(settings.comboNumActions.Text) - 1
			lstActions(i).Visible = True
		Next i
		For i = CInt(settings.comboNumActions.Text) To 11
			lstActions(i).Text = "Random"
			lstActions(i).Visible = False
		Next i
		
		Call lstPreset_SelectedIndexChanged(lstPreset, New System.EventArgs())
		
		' load from a file if possible
		'UPGRADE_WARNING: Dir has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
		If Dir(My.Application.Info.DirectoryPath & "/actions.txt") = "" Then
			Exit Sub
		End If
		
		' read settings from disk
		FileOpen(1, My.Application.Info.DirectoryPath & "/actions.txt", OpenMode.Input)
		For i = 0 To 11
			Input(1, str_Renamed)
			lstActions(i).Text = str_Renamed
		Next i
		
		Input(1, str_Renamed)
		chkAlchemy.CheckState = CShort(str_Renamed)
		
		Input(1, str_Renamed)
		chkSetB.CheckState = CShort(str_Renamed)
		Input(1, str_Renamed)
		chkSetS.CheckState = CShort(str_Renamed)
		Input(1, str_Renamed)
		chkSetI.CheckState = CShort(str_Renamed)
		Input(1, str_Renamed)
		chkSetA.CheckState = CShort(str_Renamed)
		
		For i = 0 To num_all_actions - 8
			Input(1, str_Renamed)
			chkCard(i).CheckState = CShort(str_Renamed)
		Next i
		FileClose(1)
	End Sub
	
	Private Sub chkCard_MouseMove(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.MouseEventArgs) Handles chkCard.MouseMove
		Dim Button As Short = eventArgs.Button \ &H100000
		Dim Shift As Short = System.Windows.Forms.Control.ModifierKeys \ &H10000
		Dim X As Single = VB6.PixelsToTwipsX(eventArgs.X)
		Dim Y As Single = VB6.PixelsToTwipsY(eventArgs.Y)
		Dim Index As Short = chkCard.GetIndex(eventSender)
		Dim id As Short
		With chkCard(Index)
			If (X < 0) Or (Y < 0) Or (X > VB6.PixelsToTwipsX(.Width)) Or (Y > VB6.PixelsToTwipsY(.Height)) Then
				' do nothing
			Else
				If Val(imgCard.Tag) <> Index Then
					imgCard.Tag = Index
					'UPGRADE_WARNING: Couldn't resolve default property of object get_id_by_name(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
					id = get_id_by_name(Mid(VB6.GetItemString(Me.lstActions(0), Index), 5))
					imgCard.Image = images(id)
				End If
			End If
		End With
	End Sub
	
	'UPGRADE_WARNING: Event lstActions.SelectedIndexChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub lstActions_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles lstActions.SelectedIndexChanged
		Dim Index As Short = lstActions.GetIndex(eventSender)
		Dim id As Short
		If Me.lstActions(Index).Text <> "Random" Then
			'UPGRADE_WARNING: Couldn't resolve default property of object get_id_by_name(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			id = get_id_by_name(Mid(Me.lstActions(Index).Text, 5))
			imgCard.Image = images(id)
		End If
	End Sub
	'UPGRADE_WARNING: Event lstPreset.SelectedIndexChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub lstPreset_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles lstPreset.SelectedIndexChanged
		Dim j As Short
		For j = 0 To 11
			If default_sets(lstPreset.SelectedIndex, j) > 0 Then
				'UPGRADE_WARNING: Couldn't resolve default property of object get_sorted_name_by_id(default_sets(lstPreset.ListIndex, j)). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				'UPGRADE_WARNING: Couldn't resolve default property of object get_sorted_name_by_id(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
				lstActions(j).Text = get_sorted_name_by_id(default_sets(lstPreset.SelectedIndex, j))
			Else
				lstActions(j).Text = "Random"
			End If
		Next j
	End Sub
	
	Private Function get_sorted_name_by_id(ByVal i As Short) As Object
		'UPGRADE_NOTE: str was upgraded to str_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
		Dim str_Renamed As String
		str_Renamed = "(B) "
		If i > 31 Then str_Renamed = "(S) "
		If i > 57 Then str_Renamed = "(I) "
		If i > 82 Then str_Renamed = "(A) "
		If i = 96 Then str_Renamed = "(P) "
		str_Renamed = str_Renamed & names(i)
		'UPGRADE_WARNING: Couldn't resolve default property of object get_sorted_name_by_id. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
		get_sorted_name_by_id = str_Renamed
	End Function
End Class